package duoxiancheng;

/**
 * join 合并，插队线程
 */
public class JoinDemo {
    public static void main(String[] args) {
        new Thread(new Father()).start();
    }

}

class Father extends Thread{
    @Override
    public void run() {
        System.out.println("想抽烟，发现没烟了");
        System.out.println("让儿子去买烟");
        Thread f = new Thread(new Son());
        f.start();
        try {
            f.join();//father被阻塞
        } catch (InterruptedException e) {
            System.out.println("孩子走丢了，老爸找孩子去了");
        }
        System.out.println("爸爸收到烟，把零钱给了儿子");
    }
}

class Son extends Thread{
    @Override
    public void run() {
        System.out.println("接过老爸的钱出去了");
        System.out.println("路边有个网吧，玩了10秒");
        for (int i = 0; i <10 ; i++) {
            System.out.println(i+"秒过去了");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("赶紧买烟去");
        System.out.println("买了一包利群");
    }
}